package com.example.backend.mapper;


import com.example.backend.pojo.Review;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReviewMapper {


    @Select("select * from review,foodorder where review.orderid=foodorder.orderid and foodorder.userid= #{userid}")
    List<Review> getallbyuserid(Integer userid);

    @Insert("INSERT INTO review(orderid,review,point,image,createtime)    VALUES (#{orderid},#{review},#{point},#{image},now())")
    @Options(useGeneratedKeys = true, keyProperty = "reviewid")
    void addreview(Review review);

    @Select("select * from review,foodorder where review.orderid=foodorder.orderid and foodorder.restaurantid=#{resid}")
    List<Review> getallbyresid(Integer resid);

    @Update("update review set reply=#{reply} where reviewid=#{reviewid}")
    void reply(@Param("reviewid")Integer reviewid, @Param("reply")String reply);

    @Select("SELECT ROUND(avg(point), 1) FROM foodorder,review where foodorder.orderid=review.orderid and foodorder.restaurantid= (SELECT restaurantid from foodorder where orderid=#{orderid})")
    Float avgpoint(Integer orderid);

    @Select("select * from review where reviewid=#{reviewid}")
    Review getByid(Integer reviewid);
}
